package guan.bean;

import java.io.Serializable;

import javax.persistence.Embeddable;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;

@Embeddable
public class ResCodePK implements Serializable {

	private static final long serialVersionUID = 1L;

	private String value;
	@ManyToOne(fetch = FetchType.EAGER, optional = false)
	@JoinColumns({ @JoinColumn(name = "resCodeTypeId", referencedColumnName = "id") })
	private ResCodeType resCodeType;

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;

	}

	public ResCodePK() {
	}

	public ResCodePK(String value, ResCodeType resCodeType) {
		this.value = value;
		this.resCodeType = resCodeType;
	}

	public ResCodeType getResCodeType() {
		return resCodeType;
	}

	public void setResCodeType(ResCodeType resCodeType) {
		this.resCodeType = resCodeType;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		} else {
			if (!(obj instanceof ResCodePK)) {
				return false;
			} else {
				ResCodePK pk = (ResCodePK) obj;
				if (this.getResCodeType() == null || this.getValue() == null) {
					return false;
				} else {
					if (this.getValue().equals(pk.getValue())
							&& this.getResCodeType().getId() == pk
									.getResCodeType().getId()) {
						return true;
					} else {
						return false;
					}
				}
			}
		}
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result
				+ ((resCodeType == null) ? 0 : resCodeType.getId().hashCode());
		result = PRIME * result + ((value == null) ? 0 : value.hashCode());
		return result;

	}

}
